package jps_s10996_s7175.result;

import java.util.ArrayList;
import java.util.List;

import edu.pjwstk.jps.result.ISingleResult;
import edu.pjwstk.jps.result.IStructResult;

public class StructResult extends SingleResult implements IStructResult {

	ArrayList<ISingleResult> elements;

	public StructResult() {
		this.elements = new ArrayList<ISingleResult>();
	}

	public StructResult(ISingleResult... args) {
		this.elements = new ArrayList<ISingleResult>();
		for (ISingleResult arg : args) {
			elements.add(arg);
		}
	}

	public void add(ISingleResult res) {
		this.elements.add(res);
	}

	@Override
	public List<ISingleResult> elements() {
		return this.elements;
	}

	@Override
	public String stringme() {
		String result = "";
		int i = 0;
		result += "struct(";
		for (ISingleResult item : elements) {
			if (i > 0) {
				result += ", ";
			} // separator
			result += i + "=" + ((SingleResult) item).stringme();
			++i;
		}
		result += ")";

		return result;

	}
	
	@Override
	public String toString() {
		String result = "";
		int i = 0;
		result += "struct(";
		for (ISingleResult item : elements) {
			if (i > 0) {
				result += ", ";
			} // separator
			result += (item);
			++i;
		}
		result += ")";

		return result;

	}
	
	@Override
	public int compareTo(SingleResult o) {
		if ( o instanceof StructResult ) {
			int result = 0;
			
			if ( this.elements.size() == ((StructResult)o).elements.size()) {
				for ( int i = 0 ; i < this.elements.size() ; ++i) {
					
					if ( this.elements.get(i).getClass() != ((StructResult)o).elements.get(i).getClass() ) {
						return -1;
					} else {
						int iR = ((SimpleResult)this.elements.get(i)).compareTo(((SimpleResult)((StructResult)o).elements.get(i)));
						if (iR != 0) {
							return iR;
						}
					}

				}
			} else {
				result = -1;
			}
			
			return result;
		} else {
			return -1;
		}
		
	}

}
